package com.example.firststory;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class SeleccionarHistoria extends Activity {

	Intent traspaso;
	TextView titulo, paginaMax, paginaAct;
	ImageButton atras;
	Button historia1, historia2, historia3;
	Bundle extras;
	Animation animacion;
	Handler handl;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_seleccionar_historia);

		getReferencias();
		listenersBotones();

	}

	public void onBackPressed() {

	}

	protected void onNewIntent(Intent data) {

		setActivity(Historia.class);

	}

	protected void getReferencias() {

		historia1 = (Button) findViewById(R.id.btnHistoria1);
		historia2 = (Button) findViewById(R.id.btnHistoria2);
		historia3 = (Button) findViewById(R.id.btnHistoria3);
		atras = (ImageButton) findViewById(R.id.atrasSel);
		
		titulo = (TextView) findViewById(R.id.tvTituloSel);
		paginaMax = (TextView) findViewById(R.id.tvPagSelDe);
		paginaAct = (TextView) findViewById(R.id.tvPagSelPor);
		
		Config.setTypefaceRegular(this, paginaMax);
		Config.setTypefaceNegrita(this, paginaAct);
		Config.setTypefaceNegrita(this, titulo);
		
		Config.setTypefaceRegular(this, historia1);
		Config.setTypefaceRegular(this, historia2);
		Config.setTypefaceRegular(this, historia3);
		
		setActivity(Historia.class);
		
		animacion = AnimationUtils.loadAnimation(this, R.anim.clic_btn);

		handl = new Handler();
	}

	protected void listenersBotones() {

		historia1.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				traspaso.putExtra("Historia", 1);
				
				cambiarActivity();

			}
		});
		
		historia1.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {

				animacion.reset();
				historia1.startAnimation(animacion);
				
				return false;
			}
		});

		historia2.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				traspaso.putExtra("Historia", 2);
				cambiarActivity();

			}
		});

		historia3.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				traspaso.putExtra("Historia", 3);
				cambiarActivity();

			}
		});
		
		atras.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				setActivity(Inicio.class);
				cambiarActivity();

			}
		});

	}

	protected void setActivity(Class clase) {

		traspaso = new Intent(this, clase);

	}

	protected void cambiarActivity() {

		traspaso.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
		
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		startActivity(traspaso);
		overridePendingTransition(R.anim.zoom_back_in, R.anim.zoom_back_out);

	}
}
